
package artistic;

import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 * Color picking tool
 * 
 * @author Mikael Andersson
 * @author Rurik Högfeldt
 */

public class PickTool implements PaintTool
{
    private ToolBox toolBox;
    
    public PickTool(ToolBox toolBox)
    {
        this.toolBox = toolBox;
    }

    public Icon getIcon() {
        URL url = getClass().getResource("images/pickicon.png");
        return new ImageIcon(url);
    }

    public void mouseCallback(PaintWindow target, MouseEvent e) {
        int x = e.getX();
        int y = e.getY();

        PaintImage image = target.getImage();
        TiledCanvas canvas = image.getActiveLayer();

        if(e.getID() == MouseEvent.MOUSE_PRESSED ||
           e.getID() == MouseEvent.MOUSE_DRAGGED)
        {
            //Ignore alpha channel
            int color = canvas.getPixel(x, y) & 0x00ffffff;
            toolBox.getColorChooser().setColor(color);
        }
    }

    public void mouseWheelCallback(PaintWindow target, MouseWheelEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

}
